<?php

  defined('ACC') || exit('Acc define');
  class orderInfoModel extends Model{
       protected $table = 'orderinfo';
       protected $pk = 'order_id';
       public $fields = array(
           'order_id','order_sn','zone','address','zipcode','reciver','email','tel','mobile',
           'building','best_time','add_time','order_amount','pay','user_id','user_name'
       );

       public $rule = [
            ['reciver',1,'收货人姓名必填','required',''],
            ['email',1,'邮箱有误','email',''],
            ['pay',1,'支付方式有误','between','3,4'],
       ];


       //自动生成订单编码
      public function autoSn(){
          $str = 'OI' . date('Ymd') . mt_rand(10000,99999);

          //查询订单编号在数据库中是否存在
          $sql = 'select count(*) from ' . $this->table . '  where order_sn = "' . $str . '"';
          return $this->db->getone($sql)?$this->autoSn():$str;
      }

      //撤销订单
      public function invoke($orderId){
          $this->del($orderId);  //先删订单

          $sql = 'delete from ordergoods where order_id = ' . $orderId;  //再删订单对应的商品

          return $this->db->query($sql);
      }


  }